﻿namespace WMS6.Web.Common
{
    using System;
    using System.Threading;
    using WMS6.Web;
    using WMS6.Web.OutboundService2Ref;

    public class ActionAjax : BasePage
    {
        private string ID = string.Empty;
        private PubParasInfo pubParasInfo = null;
        private Thread th = null;

        private void AjaxResponse(string StrHtml)
        {
            base.Response.Clear();
            base.Response.StatusCode = 200;
            base.Response.StatusDescription = "OK";
            base.Response.ContentType = "text/html";
            base.Response.Write(StrHtml);
            base.Response.Flush();
            base.Response.End();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            string CS40000 = base.Request.QueryString["Type"];
            if ((CS40000 != null) && (CS40000 == "WaveTemplate"))
            {
                this.WaveTemplate();
            }
        }

        private void WaveTemplate()
        {
            this.ID = base.Request.QueryString["ID"];
            this.pubParasInfo = new PubParasInfo();
            this.pubParasInfo.UserID = base.UserInfo.UserID;
            this.pubParasInfo.UserLanguage = base.UserInfo.Preference.Lang;
            this.pubParasInfo.CurrentWH = base.UserInfo.CurrentWH;
            this.th = new Thread(new ThreadStart(this.WaveTemplateAction));
            this.th.Start();
            this.AjaxResponse("生成波次模板操作已经提交至服务器!");
        }

        private void WaveTemplateAction()
        {
            OutboundService2Client client = new OutboundService2Client("WSHttpBinding_IOutboundService2");
            try
            {
                client.CreatedWaveByWaveTemplate(this.ID, this.pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            finally
            {
                this.th.Abort();
            }
        }
    }
}

